# !/usr/bin/env python
# -*- coding:utf-8 -*-
'''
@File  : readConfig.py
@Author: canx
@Date  : 2018/8/13 17:01
@Desc  : 读取 .conf 后缀的文件
'''

import configparser
import os
import sys

print('path', sys.path[0])
os.chdir(sys.path[0])

cf = configparser.ConfigParser()

# cf.read("test.ini")
cf.read("configfile/config.ini")

#return all section
secs = cf.sections()
print ('sections:', secs, type(secs))
opts = cf.options("config")
print ('options:', opts, type(opts))
kvs = cf.items("config")
print ('config:', kvs)

#read by type
ip = cf.get("config", "ip")
port = cf.getint("config", "port")
username = cf.get("config", "username")
password = cf.get("config", "password")
dburl = cf.get("config", "dburl")

print(ip, port, username, password, dburl)